Skip to content

Fix codegen crash on list text segments and support latest Figma API - #49

Merged
owjs3901 merged 9 commits into
mainfrom
codegen-error-diagnostics
Sep 3, 2026
Merged

Fix codegen crash on list text segments and support latest Figma API#49
owjs3901 merged 9 commits into
mainfrom
codegen-error-diagnostics

Conversation

@owjs3901

@owjs3901 owjs3901 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Problem

Codegen crashed in Dev Mode with an unhandled promise rejection:

unhandled promise rejection: TypeError: cannot read property 'type' of undefined
    at <anonymous> (PLUGIN_37_SOURCE:1:243768)
    at map (native)

The bundle is minified, so the stack trace was unusable and the panel showed nothing at all.

Root cause

renderText read seg.listOptions.type unconditionally. Figma returns listOptions as
undefined — not { type: 'NONE' } — for the non-list segments of a TEXT node that
also contains a bulleted or numbered list:

[0] listOptions=undefined              <- plain heading line
[1] listOptions={"type":"UNORDERED"}   <- the list

Changes

Fix crash on list text segments — a missing listOptions now means "not a list".

Add codegen diagnostics (codegen/utils/diagnostics.ts) — instead of relying on minified
stack traces, each codegen step tags the error it observes with the node it was processing.
Tagging is zero-cost on the success path; nothing is formatted until an error escapes.

Trace codegen stepsbuildTree, addComponentTree, renderTree, renderText and every
prop getter are tagged, so a failure names the exact node and the exact getter.

Report codegen errors in code panel — the generate handler now catches, logs, and returns
the report as a PLAINTEXT block, so a crash produces something copy-pasteable instead of a
silent rejection:

========================================================================
DEVUP UI CODEGEN ERROR - copy this whole block and send it to the maintainer
========================================================================
error    : TypeError: cannot read property 'type' of undefined
language : devup-ui
selected : FRAME "A : SET-NOTICE-DETAIL" (4283:21277)
failing  : TEXT "1. ..." (4283:21286)

--- codegen path (innermost first) ---
  1. renderText :: TEXT "1. ..." (4283:21286)
  2. buildTree :: TEXT "1. ..." (4283:21286)
  3. buildTree :: FRAME "Frame 1321314982" (4283:21283)
  ...

--- failing node ---
  id / name / type / visible / width / height / characters
  children / fills / strokes / effects / reactions   (len + item types)
  styledTextSegments: len=2
    [0] listOptions=undefined ...
    [1] listOptions={"type":"UNORDERED"} ...

That report is what identified this bug.

Dependency update

typescript@7, @figma/plugin-typings@1.137, @rspack/*@2.2, @biomejs/biome@2.5,
@types/bun@1.4. Two API unions widened and broke tsc --noEmit; both are fixed by supporting
the new values rather than pinning back:

Support new auto layout distributionsprimaryAxisAlignItems gained SPACE_EVENLY and
SPACE_AROUND. They are now mapped to justify-content: space-evenly / space-around.
Previously these frames silently lost their justifyContent prop entirely.

Exclude motion easing from color variablesVariableValue gained MotionEasing, which
figma.util.rgba() does not accept. A COLOR variable can never resolve to one at runtime, so it
is narrowed out via a new isMotionEasing guard folded into the existing boolean/number
check — no new runtime branch, no as any.

Note: gap is currently suppressed only for SPACE_BETWEEN. SPACE_EVENLY / SPACE_AROUND
still emit it. If Figma also ignores itemSpacing in those modes, the suppression should be
extended — the current behaviour is pinned by a test so the change is easy to make later.

Verification

  • Regression test written first, reproducing the exact failure
    (TypeError: undefined is not an object (evaluating 'seg.listOptions.type'), at map), then
    passing after the fix.
  • bun run test (tsc --noEmit && bun test --coverage) — 1005 pass / 0 fail, 268 snapshots
    unchanged, coverage threshold (100%) held.
  • biome check --error-on-warnings clean, rspack build succeeds on the new toolchain.
  • The built dist/code.js was driven the same way Figma drives it, with the reported node shape
    (segment [0] listOptions: undefined + segment [1] UNORDERED): codegen now succeeds and
    emits <Text as="ul"> ... <li>.

Ultraworked with Sisyphus

owjs3901 and others added 7 commits September 3, 2026 19:07
Figma returns listOptions as undefined for the non-list segments of a TEXT node that also contains a bulleted list, so reading .type threw and the whole codegen rejected.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
The bundle is minified, so Figma stack traces are unreadable. Tag errors with the node being processed and format a copyable report instead.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Tag buildTree, addComponentTree, renderTree, renderText and every prop getter so a failure names the exact node and getter.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
A throw surfaced only as an unhandled promise rejection. Catch it and return the diagnostic report as a PLAINTEXT block users can copy.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Figma added SPACE_EVENLY and SPACE_AROUND to primaryAxisAlignItems; map them to the matching justify-content values instead of dropping the prop.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
VariableValue gained MotionEasing with the Motion API, so figma.util.rgba no longer accepts it. Narrow it out alongside the existing boolean/number guard.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@owjs3901 owjs3901 changed the title Fix crash on list text segments Fix codegen crash on list text segments and support latest Figma API Sep 3, 2026
owjs3901 and others added 2 commits September 3, 2026 19:40
Every codegen cache is keyed by node.id, so the reset list must stay complete. Move it into one function instead of an inline block only code-impl knows about.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
beforeEach reset only 5 of the 12 codegen caches, so ids reused across test files (status-error in check-asset-node.test.ts, status-success in codegen.test.ts) leaked a stale sameColor and broke variant merging depending on file order.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@owjs3901
owjs3901 merged commit 29c8c2b into main Sep 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant